
import java.awt.Container;
import javax.swing.JLabel;
import restaurantguide.StarRater;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * evaluaterest.java
 *
 * Created on 27 Φεβ 2012, 2:11:37 πμ
 */
/**
 *
 * @author karolos
 */
public class evaluaterest extends javax.swing.JPanel {

    
    private int restaurantid;
    private String userusername;
    private boolean flag;

    /** Creates new form evaluaterest */
    public evaluaterest() {
        initComponents();

    }

    public int getRestaurantid() {
        return restaurantid;
    }

    public void setRestaurantid(int restaurantid) {
        this.restaurantid = restaurantid;
    }

    public JLabel getRestname() {
        return restname;
    }

    public void setRestname(String restname) {
        this.restname.setText(restname);
    }

    public StarRater getStarRater1() {
        return starRater1;
    }

    public void setStarRater1(StarRater starRater1) {
        this.starRater1 = starRater1;
    }

    public StarRater getStarRater2() {
        return starRater2;
    }

    public void setStarRater2(StarRater starRater2) {
        this.starRater2 = starRater2;
    }

    public StarRater getStarRater3() {
        return starRater3;
    }

    public void setStarRater3(StarRater starRater3) {
        this.starRater3 = starRater3;
    }

    public StarRater getStarRater4() {
        return starRater4;
    }

    public void setStarRater4(StarRater starRater4) {
        this.starRater4 = starRater4;
    }

    public JLabel getVathmos() {
        return vathmos;
    }

    public void setVathmos(JLabel vathmos) {
        this.vathmos = vathmos;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    

   

    public String getUserusername() {
        return userusername;
    }

    public void setUserusername(String userusername) {
        this.userusername = userusername;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        restname = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        starRater1 = new restaurantguide.StarRater();
        starRater2 = new restaurantguide.StarRater();
        starRater3 = new restaurantguide.StarRater();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        vathmos = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        starRater4 = new restaurantguide.StarRater();
        jButton2 = new javax.swing.JButton();

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Αξιολόγηση Εστιατορίου:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(19, 28, -1, -1));

        restname.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        restname.setText("jLabel2");
        jPanel1.add(restname, new org.netbeans.lib.awtextra.AbsoluteConstraints(217, 28, -1, -1));

        jLabel3.setText("Ποιότητα:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(127, 68, -1, -1));

        jLabel4.setText("Τιμές:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(146, 100, -1, -1));

        jLabel5.setText("Χρόνος εξυπηρέτησης:");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(65, 125, -1, -1));

        starRater1.setStars(10);

        javax.swing.GroupLayout starRater1Layout = new javax.swing.GroupLayout(starRater1);
        starRater1.setLayout(starRater1Layout);
        starRater1Layout.setHorizontalGroup(
            starRater1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        starRater1Layout.setVerticalGroup(
            starRater1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jPanel1.add(starRater1, new org.netbeans.lib.awtextra.AbsoluteConstraints(192, 68, -1, -1));

        starRater2.setStars(10);

        javax.swing.GroupLayout starRater2Layout = new javax.swing.GroupLayout(starRater2);
        starRater2.setLayout(starRater2Layout);
        starRater2Layout.setHorizontalGroup(
            starRater2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        starRater2Layout.setVerticalGroup(
            starRater2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jPanel1.add(starRater2, new org.netbeans.lib.awtextra.AbsoluteConstraints(192, 98, -1, -1));

        starRater3.setStars(10);

        javax.swing.GroupLayout starRater3Layout = new javax.swing.GroupLayout(starRater3);
        starRater3.setLayout(starRater3Layout);
        starRater3Layout.setHorizontalGroup(
            starRater3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        starRater3Layout.setVerticalGroup(
            starRater3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jPanel1.add(starRater3, new org.netbeans.lib.awtextra.AbsoluteConstraints(192, 125, -1, -1));

        jButton1.setLabel("Υποβολή");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(167, 169, -1, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Μέση βαθμολογία:");

        vathmos.setFont(new java.awt.Font("Tahoma", 1, 12));
        vathmos.setText("jLabel7");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel8.setText("/");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel9.setText("10");

        starRater4.setEnabled(false);
        starRater4.setStars(10);

        javax.swing.GroupLayout starRater4Layout = new javax.swing.GroupLayout(starRater4);
        starRater4.setLayout(starRater4Layout);
        starRater4Layout.setHorizontalGroup(
            starRater4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
        starRater4Layout.setVerticalGroup(
            starRater4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jButton2.setText("Κλείσιμο");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(starRater4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(62, 62, 62)
                                .addComponent(vathmos)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(167, 167, 167)
                        .addComponent(jButton2)))
                .addContainerGap(117, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(vathmos)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGap(28, 28, 28)
                .addComponent(starRater4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(40, 40, 40))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        DBManager db=mainframe.getDB();
        float quality=starRater1.getSelection();
            float prices=starRater2.getSelection();
            float servicetime=starRater3.getSelection();
            float avg=(quality+prices+servicetime)/3;
            starRater4.setRating(avg);
            vathmos.setText(Float.toString(avg));

        if (flag==true){

            db.updateeval(quality,prices,servicetime,userusername,restaurantid);
        }
        else{
            flag=true;
             db.createeval(quality,prices,servicetime, restaurantid, userusername);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Container c = (Container)this;
    while( c.getParent()!=null ) {
    c=c.getParent();
    }
   c.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel restname;
    private restaurantguide.StarRater starRater1;
    private restaurantguide.StarRater starRater2;
    private restaurantguide.StarRater starRater3;
    private restaurantguide.StarRater starRater4;
    private javax.swing.JLabel vathmos;
    // End of variables declaration//GEN-END:variables
}
